import { Button, Modal, message, Spin } from 'antd';

const confirm = Modal.confirm;
import { WeaErrorPage, WeaTools, WeaAlertPage, WeaAuth } from 'ecCom';
import { WeaTableNew, WeaSwitch } from 'comsMobx';

const WeaTable = WeaTableNew.WeaTable;
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

@observer
class CustomerShare extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }
  componentDidMount() {
    	const { contentStore, location: { query } } = this.props;
    contentStore.getShareSettingList(query);
    contentStore.getShareSettingRightMenu({ selectType: 'shareinfo', customerId: query.customerId });
  }
  componentWillUnmount() {
    // const {contentStore} = this.props;
    // contentStore.clearStatus();
  }
  render() {
    const { contentStore } = this.props;
    const { shareAuth: { verified, hasRight }, shareTableStore, shareStore, saveShareSetting, customerId, shareCondition = [] } = contentStore;
    // console.log(shareCondition)
    if (verified && !hasRight) {
      return (<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@hp8crh`} >
        <div style={{ color: '#000' }}>
          {getLabel(2012, '对不起，您暂时没有权限！')}
        </div>
      </WeaAlertPage>
      );
    }
    if (verified && hasRight) {
      return (
        <div>
          <WeaTable
            ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@mh4av3`}
            comsWeaTableStore={shareTableStore}
            hasOrder
            needScroll
            onOperatesClick={this.onOperatesClick.bind(this)}
          />
          <WeaAuth
            ecId={`${this && this.props && this.props.ecId || ''}_WeaAuth@e60puv`}
            style={{ width: 800, height: 500 }}
            visible={shareStore.visible}
            conditions={toJS(shareCondition)}
            title={getLabel(18645, '添加共享')}
            icon={'icon-coms-crm'}
            iconBgcolor="#96358a"
            onOk={(v) => {
              saveShareSetting({ ...v, customerId });
              shareStore.handleShareDialog(false);
            }}
            onCancel={() => {
              shareStore.handleShareDialog(false);
            }}
          />
        </div>
      );
    }
    return <div />;
  }

  onOperatesClick(record, index, operate, flag) {
    const { contentStore } = this.props;
    if (flag == '0') {
      contentStore.shareSettingDelete({ id: record.randomFieldId }, contentStore.customerId);
    }
  }
}

export default WeaTools.tryCatch(React,
  props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@b0t4rk`} msg={props.error ? props.error : getLabel(129417, '服务器运行出错，请联系系统管理员！')} />,
  { error: '' },
)(CustomerShare);
